import FingerprintJS from'@fingerprintjs/fingerprintjs'
import CryptoJS  from 'crypto-js'
const PaddingBytes = (n) => (n <= 9 ? `0${n}` : n);
export default {
  data () {
    return {
      title: '埋点',
      message: "xuxiao is boy",
      previewVisible: false,
      fileList:[
      ],
      previewImage:'',
      visible: false,
      cover:[],
    }
  },
  // beforeCreate () {
  //   console.group('beforeCreate 创建前状态===============》');
  //
  // },
  // created () {
  //   console.group('created 创建完毕状态===============》');
  //
  // },
  // beforeMount () {
  //   console.group('beforeMount 挂载前状态===============》');
  //
  // },
  // mounted () {
  //   console.group('mounted 挂载结束状态===============》');
  //
  // },
  // beforeUpdate () {
  //   console.group('beforeUpdate 更新前状态===============》');
  //
  // },
  // updated () {
  //   console.group('updated 更新完成状态===============》');
  //
  // },
  // beforeDestroy () {
  //   console.group('beforeDestroy 销毁前状态===============》');
  //
  // },
  // destroyed () {
  //   console.group('destroyed 销毁完成状态===============》');
  // },
  methods: {
    /***
     * 把文件转为base64
     * @param file
     * @returns {Promise<any>}
     */
     getBase64(file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader()
    reader.readAsDataURL(file)
    reader.onload = () => resolve(reader.result)
    reader.onerror = (error) => reject(error)
  })
},
    async handlePreview(file) {
      if (!file.url && !file.preview) {
        file.preview = await getBase64(file.originFileObj)
      }
      this.previewImage = file.url || file.preview
      this.previewVisible = true
    },
    handleChange({ fileList }) {
      this.fileList = fileList

      this.cover = [];
      fileList.forEach((item) => {
        if (item?.response?.code === 200) {
          this.cover.push(item?.response?.data?.accessPath)
        }
      })
    },
    handleCancel(e) {
      console.log('Clicked cancel button')
      this.visible = false
      // this.cbClose()
    },

    timeFormatsss(d) {
      d = new Date(new Date(new Date().setHours(0, 0, 0, 0)));
      let getMonth = d.getMonth() + 1;
      let getDate = d.getDate();
      let getHours = d.getHours();
      let getMinutes = d.getMinutes();
      let getSeconds = d.getSeconds();

      return `${d.getFullYear()}-${PaddingBytes(getMonth)}-${PaddingBytes(getDate)} ${PaddingBytes(getHours)}:${PaddingBytes(getMinutes)}:${PaddingBytes(getSeconds)}`
    },
    PostPoint (obj = '') {
      console.log('我是混入方法', this.title, obj)
    },
    async getBrowserFingerprint(){

      const ddd =  await  FingerprintJS.load().then(fp => fp.get()) .then(result => result )
      localStorage.setItem(CryptoJS.AES.encrypt('CryptoJSFingerprintJS', 'CryptoJS and sokilngs FingerprintJS').toString(),CryptoJS.AES.encrypt(JSON.stringify(ddd), 'secret key 123').toString())
      return  ddd
      // console.log(ddd,'ddd')
    }

  },
}
